/***************************************************************
*  Copyright (c) 2007 by GroupMe! Team (www.groupme.net)
*  All rights reserved.
*
*  This file is part of the GroupMe! Project. Source code of 
*  this project is closed and redistribution of this code is
*  prohibited. 
*  
*  Contact: http://www.groupme.net
*
*  This copyright notice MUST APPEAR in all copies of the file!
***************************************************************/
package net.groupme.stats;

import net.groupme.model.ObjectFactory;
import net.groupme.model.dao.DATABASE_CONSTANTS;
import net.groupme.utils.sql.SelectQueryUtility;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * created on 08.11.2007
 * 
 * This class provides some functionality to manage stats about GroupMe.
 * 
 * @author Mischa Frank, <a href="mailto:code@planetfrank.net">code@planetfrank.net</a>
 * @author last edited by: $Author: fabian $
 * 
 * @version $Revision: 1.2 $ $Date: 2007-11-08 18:40:20 $
 */
public class StatManager {
	
	/** Logger for this class and subclasses */
	protected final Log logger = LogFactory.getLog(getClass());
	
	private int users = 0;
	
	private int groups = 0;
	
	private int resources = 0;
	
	private int tags = 0;

	/**
	 * Creates an empty {@link StatManager} instance.
	 */
	public StatManager(){
		super();
		String query = "SELECT count(*) FROM `"+ DATABASE_CONSTANTS.TABLE_USER + "`";
		users = SelectQueryUtility.getSingleIntFromTable(ObjectFactory.ds, query, "count(*)");
		query = "SELECT count(*) FROM `"+ DATABASE_CONSTANTS.TABLE_RESOURCE + "` WHERE type='"+ DATABASE_CONSTANTS.RESOURCE_TYPE_GROUP +"'";
		groups = SelectQueryUtility.getSingleIntFromTable(ObjectFactory.ds, query, "count(*)");
		query = "SELECT count(*) FROM `"+ DATABASE_CONSTANTS.TABLE_RESOURCE + "`" ;
		resources = SelectQueryUtility.getSingleIntFromTable(ObjectFactory.ds, query, "count(*)");
		query = "SELECT count(*) FROM `"+ DATABASE_CONSTANTS.TABLE_TAG + "`";
		tags = SelectQueryUtility.getSingleIntFromTable(ObjectFactory.ds, query, "count(*)");
		
		logger.info("User: " + users + " Groups: " + groups + " Resources: " + resources + " Tags: " + tags);
	}

	/**
	 * This method returns the groups of a StatManager object.
	 * @return the groups
	 */
	public Integer getGroups() {
		return groups;
	}

	/**
	 * This method sets the groups of a StatManager object.
	 * @param groups the groups to set
	 */
	public void setGroups(int groups) {
		this.groups = groups;
	}

	/**
	 * This method returns the ressources of a StatManager object.
	 * @return the ressources
	 */
	public Integer getResources() {
		return resources;
	}

	/**
	 * This method sets the ressources of a StatManager object.
	 * @param ressources the ressources to set
	 */
	public void setResources(int resources) {
		this.resources = resources;
	}

	/**
	 * This method returns the tags of a StatManager object.
	 * @return the tags
	 */
	public Integer getTags() {
		return tags;
	}

	/**
	 * This method sets the tags of a StatManager object.
	 * @param tags the tags to set
	 */
	public void setTags(int tags) {
		this.tags = tags;
	}

	/**
	 * This method returns the users of a StatManager object.
	 * @return the users
	 */
	public Integer getUsers() {
		return users;
	}

	/**
	 * This method sets the users of a StatManager object.
	 * @param users the users to set
	 */
	public void setUsers(int users) {
		this.users = users;
	}

}
